﻿@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />


<form class="layui-form" action="">

	<div class="layui-form-item">
		<label class="layui-form-label">账号：</label>
		<div class="layui-input-block">
			<input type="text"
				   name="userName"
				   lay-verify="required"
				   placeholder="请输入"
				   class="layui-input"
				   style="width:250px" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">密码：</label>
		<div class="layui-input-block">
			<input type="password"
				   name="userPass"
				   lay-verify="required"
				   autocomplete="off"
				   placeholder="请输入"
				   class="layui-input"
				   lay-affix="eye"
				   style="width:250px" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">昵称：</label>
		<div class="layui-input-block">
			<input type="text"
				   name="userNickname"
				   lay-verify="required"
				   autocomplete="off"
				   placeholder="请输入"
				   class="layui-input" style="width:250px" />
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">联系方式:</label>
			<div class="layui-input-inline layui-input-wrap">
				<input type="tel"
					   name="userPhone"
					   lay-verify="required|phone"
					   autocomplete="off"
					   lay-reqtext="请填写手机号"
					   lay-affix="clear"
					   class="layui-input demo-phone" style="width:250px" />
			</div>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">状态：</label>
		<div class="layui-input-block">
			<input type="radio" name="userStatus" value="1" title="启用" checked />
			<input type="radio" name="userStatus" value="0" title="禁用" />
		</div>
	</div>


	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="submit" class="layui-btn" lay-submit lay-filter="addUser">
				立即提交
			</button>
			<button type="reset" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">关闭</button>
		</div>
	</div>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>
<script>

		//关闭弹框
		function closeWorkstation() {
				// 添加成功后的逻辑，例如关闭弹窗，刷新表格等
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				window.parent.location.reload(); // 刷新父页
				parent.layer.close(index); //再执行关闭
				setTimeout(function () { parent.layer.close(index) }, 50000);//延迟s
		}

	layui.use(['form','util'],function (){
		   var form=layui.form;

		   function closeWindow(){
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				window.parent.location.reload(); // 刷新父页
				parent.layer.close(index); //再执行关闭
				setTimeout(function () { parent.layer.close(index) }, 30000);//延迟s
		   }

			 // 提交事件
	  form.on('submit(addUser)', function (data) {
		var field = data.field; // 获取表单字段值
			 $.ajax({
				 url:'/RBAC/AddUser',
				 data:field,
				 type:'post',
				 dataType:'json',
				 success:function (res){
					 console.log(11111111111111,res)
					   if (res > 0) {
						   layer.alert('添加成功', { title: '操作结果' }, function () {
								// 添加成功后的逻辑，例如关闭弹窗，刷新表格等
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								window.parent.location.reload(); // 刷新父页
								parent.layer.close(index); //再执行关闭
								setTimeout(function () { parent.layer.close(index) }, 50000);//延迟s
							})
					   }
					  else {
						  layer.alert("添加失败！");
					  }
				 }
			 })
		return false; // 阻止默认 form 跳转
	  });
	})

</script>